<%--
  - Author		:	Jaewon Choi
  - Description	:	
  --%>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/pages/includes/taglibs.jspf" %>
<%@ include file="/WEB-INF/pages/includes/variables.jspf" %>
<%@ include file="/WEB-INF/pages/includes/doctype.jspf" %>
<html>
	<head>
<%@ include file="/WEB-INF/pages/includes/metatags.jspf" %>
		<title><fmt:message key="pages.title" /></title>
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirStyles}/common.css" />" />
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirScripts}/jqueryUi/css/ui-lightness/jquery-ui-1.8.21.custom.css" />" />

		<script type="text/javascript" src="<c:url value="${dirScripts}/common.js" />"></script>
		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-1.7.2.min.js" />"></script>
		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-ui-1.8.21.custom.min.js" />"></script>
		<script type="text/javascript">
			function goAction(idx){
				if(idx == "" || ! idx){
					return false;
				}
				document.frm.idx.value= idx;
				document.frm.submit();
			}
			
			function goPage(page){
				document.searchFrm.page.value = page;
				document.searchFrm.submit();
			}

		</script>
	</head>
	<body>
		<div class="bodyWrap">
<%@ include file="/WEB-INF/pages/includes/header.jsp" %>
<%@ include file="/WEB-INF/pages/includes/left.jsp" %>
			<div class="contWrap">
				<div class="menuTitle">브랜드 목록</div>
				<div class="searchWrap">
					<form name="searchFrm" action="<c:url value="/category/list.do" />" method="post">
						<input type="hidden" name="maxnum" value="${maxnum}" />
						<input type="hidden" name="page" value="${page}" />
						<ul  class="lineBlock">
							<li>
								<font style="width: 50px;">브랜드명</font>
								<input type="text" name="name" value="${param.name}" placeholder="브랜드명" />								
							</li>
						</ul>			
					</form>
					<div style="text-align: left;">
						<input class="btn" type="submit" value="검색" onclick="javascript:document.searchFrm.page.value=1;" />
					</div>
				</div>
				<form name="removeFrm" method="post" action="<c:url value="/category/remove.do" />">
					<input type="hidden" name="maxnum" value="${maxnum}" />
					<input type="hidden" name="page" value="${page}" />
					<input type="hidden" name="searchName" value="${param.name}" />
					<input type="hidden" name="fAct" value="remove">
					<table class="listTbl">					
							<colgroup>
								<col width="35px;" />
								<col width="80px;" />
								<col width="*" />
								<col width="150px" />	
							</colgroup>
							<thead>
								<tr>
									<th><input type="checkbox" onclick="javascript:$('.removeChk').attr('checked', $(this).is(':checked')?true:false);"></th>								
									<th>No.</th>
									<th>브랜드명</th>
									<th>등록일시</th>			
								</tr>
							</thead>											
						<c:choose>
							<c:when test="${categoryListTotalCnt ne 0}">
								<tbody>
									<c:forEach items="${categoryList}" var="category" varStatus="categoryStat">										
												<tr class="dataTr">			
													<td>
														<input type="checkbox" name="idx" class="removeChk" value="${category.idx}" <c:if test="${category.idx eq 1}">disabled="disabled"</c:if>>
													</td>										
													<td onclick="javascript:goAction(${category.idx});">${categoryListTotalCnt - categoryStat.index - (maxnum*(page-1))}</td>													
													<td onclick="javascript:goAction(${category.idx});" style="text-align: left; text-indent: 15px;">
														<c:out value="${category.name}" />
													</td>													
													<td onclick="javascript:goAction(${category.idx});">
														<c:catch var="e">
															<fmt:parseDate var="createdTime" pattern="yyyy-MM-dd HH:mm:ss" value="${category.createdTime}" />
															<fmt:formatDate value="${createdTime}" pattern="yyyy-MM-dd HH:mm:ss" />
														</c:catch>
														<c:if test="${not empty e}">
															${category.createdTime}
														</c:if>
													</td>													
												</tr>											
									</c:forEach>
								</tbody>
							</c:when>
							<c:otherwise>
								<tfoot>
									<tr><td colspan="6" style="text-align: center;">데이터가 없습니다.</td></tr>
								</tfoot>
							</c:otherwise>
						</c:choose>
					</table>
					<c:if test="${categoryListTotalCnt ne 0}">
						<div class="pagingWrap">
							<jsp:include page="/WEB-INF/pages/includes/paging.jsp">
								<jsp:param name="totalNum" value="${categoryListTotalCnt}" />
								<jsp:param name="pageListCnt" value="${maxnum}" />
								<jsp:param name="pageGrpCnt" value="5" />
								<jsp:param name="pageIdx" value="${page}" />
							</jsp:include>
						</div>
					</c:if>
					<c:if test="${sessionScope.userRole eq 'ROLE_ADMIN'}">
						<input type="button" class="btn" value="삭제" onclick="javascript:if(confirm('선택하신 목록을 삭제하시겠습니까?')){document.removeFrm.submit();}" />
						<input type="button" class="btn" value="등록" onclick="javascript:location.href='<c:url value="/category/form.do" />';" />
					</c:if>
				</form>
				<form name="frm" action="<c:url value="/category/detail.do" />" method="post" style="display: none;">
					<input type="hidden" name="idx" value="">
					<input type="hidden" name="maxnum" value="${maxnum}" />
					<input type="hidden" name="page" value="${page}" />
					<input type="hidden" name="searchName" value="${param.name}" />
				</form>
			</div>
<%@ include file="/WEB-INF/pages/includes/footer.jsp" %>
		</div>
	</body>
</html> 